import cv2

# 转换为灰度图

# 方法1
img1 = cv2.imread('cat_dog.jpg', cv2.IMREAD_GRAYSCALE)

# 方法2
img2  = cv2.imread('cat_dog.jpg')
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

# 方法3
# 每个像素三个通道的值取平均数
img3  = cv2.imread('cat_dog.jpg')
(row, col) = img3.shape[0:2]
for i in range(row):
  for j in range(col):
    img3[i, j] = sum(img3[i, j]) * 0.33

cv2.imshow('image1', img1)
cv2.imshow('image2', img2)
cv2.imshow('image3', img3)
cv2.waitKey(0)
cv2.destroyAllWindows()